package com.ruoyi.web.controller.activity;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.ActSchool;
import com.ruoyi.activity.service.IActSchoolService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 校级活动Controller
 * 
 * @author YZD
 * @date 2022-07-12
 */
@Controller
@RequestMapping("/activity/school")
public class ActSchoolController extends BaseController
{
    private String prefix = "activity/school";

    @Autowired
    private IActSchoolService actSchoolService;

    @RequiresPermissions("activity:school:view")
    @GetMapping()
    public String school()
    {
        return prefix + "/school";
    }

    /**
     * 查询校级活动列表
     */
    @RequiresPermissions("activity:school:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActSchool actSchool)
    {
        startPage();
        List<ActSchool> list = actSchoolService.selectActSchoolList(actSchool);
        return getDataTable(list);
    }

    /**
     * 导出校级活动列表
     */
    @RequiresPermissions("activity:school:export")
    @Log(title = "校级活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActSchool actSchool)
    {
        List<ActSchool> list = actSchoolService.selectActSchoolList(actSchool);
        ExcelUtil<ActSchool> util = new ExcelUtil<ActSchool>(ActSchool.class);
        return util.exportExcel(list, "校级活动数据");
    }

    /**
     * 新增校级活动
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存校级活动
     */
    @RequiresPermissions("activity:school:add")
    @Log(title = "校级活动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActSchool actSchool)
    {
        return toAjax(actSchoolService.insertActSchool(actSchool));
    }

    /**
     * 修改校级活动
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ActSchool actSchool = actSchoolService.selectActSchoolById(id);
        mmap.put("actSchool", actSchool);
        return prefix + "/edit";
    }

    /**
     * 修改保存校级活动
     */
    @RequiresPermissions("activity:school:edit")
    @Log(title = "校级活动", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActSchool actSchool)
    {
        return toAjax(actSchoolService.updateActSchool(actSchool));
    }

    /**
     * 删除校级活动
     */
    @RequiresPermissions("activity:school:remove")
    @Log(title = "校级活动", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actSchoolService.deleteActSchoolByIds(ids));
    }
}
